# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2015 Jeafea (<1062042200@qq.com>)
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields, api


class ResPartner(models.Model):
    """Add some fields related to commissions"""
    _inherit = "res.partner"

    # 客户/供应商关联agent来确定对应相关联的提成
    agents = fields.Many2many(
        comodel_name="res.partner", relation="partner_agents_rel",
        column1="partner_id", column2="agents_id",
        domain="[('agent', '=', True)]")
    agent = fields.Boolean(
        string="Creditor/Agent",
        help="Check this field if the partner is a creditor or an agent.")
    plan_id = fields.Many2many(
        "commission.plan",string="Commission Plan")

    # 目的是为了能够付款
    @api.onchange('agent')
    def onchange_agent(self):
        if self.agent:
            self.supplier = True
